//
//  MainTabBar.swift
//  CXCWeibo
//
//  Created by cxc on 15/6/24.
//  Copyright © 2015年 china. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    private let btnCount = 5
    
    override func layoutSubviews() {
        super.layoutSubviews()
        print(compoesButton)
        let w = bounds.width/CGFloat(btnCount)
        let rect  = CGRectMake(0, 0, w, bounds.height)
        
        var index = 0
        for sub in subviews {
            if sub is UIControl && !(sub is UIButton) {
                sub.frame = CGRectOffset(rect, CGFloat(index)*w, 0)
                index += index == 1 ? 2 :1
            }
        }
        compoesButton.frame = CGRectOffset(rect, w*2, 0)
    }
    
    
    // MARK:-懒加载
    lazy var compoesButton:UIButton = {
        let btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
    }()
}
